package com.huluobo.high3demo.mine.item;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;

import com.huluobo.high3demo.R;
import com.huluobo.high3demo.adapter.WorksAdapter;
import com.huluobo.high3demo.databinding.FragmentWorksBinding;
import com.huluobo.mvvm.baen.LoveVideoBeanResult;
import com.huluobo.mvvm.view.BaseMVVMFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LC on 2023/10/6.
 */
public class WorksFragment extends BaseMVVMFragment<FragmentWorksBinding, WorkViewModel> {
    private WorksAdapter worksAdapter;
    private List<LoveVideoBeanResult.LoveVideoBean> loveVideoBeans = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_works;
    }

    @Override
    protected void initData() {
        viewModel.loadLoveVideoList();
        viewModel.loveVideoSuccess.observe(requireActivity(), new Observer<LoveVideoBeanResult>() {
            @Override
            public void onChanged(LoveVideoBeanResult loveVideoBeanResult) {
                loveVideoBeans.clear();
                loveVideoBeans.addAll(loveVideoBeanResult.getData());
                worksAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    protected void initView() {
        dataBinding.worksRv.setLayoutManager(new GridLayoutManager(getContext(), 2));
        worksAdapter = new WorksAdapter(loveVideoBeans);
        dataBinding.worksRv.setAdapter(worksAdapter);
    }

    @Override
    protected Class<WorkViewModel> getViewModel() {
        return WorkViewModel.class;
    }
}
